/**
 * @file categories/graph/bipartite/luogu7368/main.cpp
 * @brief 二分图最小点覆盖，邻接矩阵 DFS
 * @see
 * @author Ruiming Guo (guoruiming@stu.scu.edu.cn)
 * @copyright 2022
 * @date 2022/7/16 17:09:00
 **/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const int N = 600;
int match[N];
bool vis[N], e[N][N];
int n, k;
bool dfs(int u) {
  for (int i = 1; i <= n; i++) {
    if (i == u || !e[u][i]) continue;
    if (vis[i]) continue;
    vis[i] = true;
    if (!match[i] || dfs(match[i])) {
      match[i] = u;
      return true;
    }
  }
  return false;
}
int solve() {
  memset(match, 0, sizeof(match));
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    memset(vis, false, sizeof(vis));
    if (dfs(i)) cnt++;
  }
  return cnt;
}

int main() {
  // High rating and good luck!
  cin >> n >> k;
  for (int i = 0; i < k; ++i) {
    int u, v;
    cin >> u >> v;
    e[u][v] = true;
  }
  cout << solve() << endl;
  return 0;
}
